<template>
    <el-card>
      <template #header>
        <el-row :gutter="10" style="float: right">
          <el-button @click="emit('addValidator')" type="primary">新 增</el-button>
          <el-button @click="deleteRow" :icon="Delete" type="danger" plain
            >删 除</el-button
          >
        </el-row>
      </template>
    </el-card>
      <ts-card header="编码规则列表" style="margin-top: 10px">
        <el-table
          ref="table"
          :data="dataList"
          height="600"
          @select="selectRow"
          @select-all="selectAll"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column prop="objectId" label="记录id"></el-table-column>
          <el-table-column prop="name" label="对象属性名"></el-table-column>
          <el-table-column prop="extendGroupId" label="引用别的验证ID"></el-table-column>
          <el-table-column prop="title" label="字段标题"></el-table-column>
          <el-table-column prop="matchMethodsName" label="执行的方法集合"></el-table-column>
          <el-table-column prop="tableName" label="表名"></el-table-column>
          <el-table-column  label="是否自动验证">
              <template #default="scope">
                  <el-switch v-model="scope.row.autoValidate" disabled></el-switch>
              </template>
          </el-table-column>
          <el-table-column label="操作">
            <template #default="scope">
              <el-button link type="primary" size="small" @click="edit(scope)"
                >修 改</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </ts-card>
  </template>
    <script setup>
  import { ref, defineModel, onMounted, computed, nextTick, inject } from "vue";
  import { Plus, Delete, DCaret, Edit } from "@element-plus/icons-vue";
  import { ElMessageBox ,ElMessage} from "element-plus";
  import API from "@/api/model/meta.js";
  const emit = defineEmits(["toDetail", "addValidator", "delete","update"]);
  const fileName = inject('fileName')
  const table = ref(null);
  const dataList = defineModel();
  const deleteList = ref([]);
  onMounted(() => {
  });
  const edit = (scope) => {
    emit("toDetail", scope.row);
  };
  const selectRow = (rows, row) => {
    deleteList.value = rows;
  };
  const selectAll = (rows) => {
    deleteList.value = rows;
  };
  const deleteRow = async () => {
    if (deleteList.value.length > 0) {
      let param = {
        fileName: fileName.value,
        dataList: deleteList.value.map((ele) => {
          return ele.objectId;
        }),
      };
      ElMessageBox.confirm("确定删除吗？", "提示", {
        type: "warning",
        confirmButtonText: "确定",
        confirmButtonClass: "el-button--danger",
      })
        .then(async() => {
          let res =await API.businessrule.deteleValidator.post(param);
          if (res.code == 200) {
            emit("delete");
            emit('update')
          }
        })
        .catch(() => {});
    } else {
      ElMessage({
        message: "请选择表格记录",
        type: "warning",
      });
    }
  };
  </script>
    <style lang="less" scoped></style>